package com.example.kuaizu.job;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;


/**
 * @author tangsp
 * @date 2019/10/15
 */

public abstract class BaseJob{
    public void execute() {
        MDC.put("jobName", this.getClass().getSimpleName());
        Logger logger = LoggerFactory.getLogger(this.getClass());
        logger.info("开始执行任务");
        long startTime = System.currentTimeMillis();
        try {
            this.doExecute();
        } catch (Exception e) {
            logger.error("任务执行异常", e);
        }
        long endTime = System.currentTimeMillis();
        logger.info("任务执行完毕，耗时：{}ms", endTime - startTime);
    }

    abstract void doExecute();


}
